import pymysql

class UserMysql():
    def __init__(self):
        db = {
            'host': '192.168.1.173',
            'user': 'root',
            'password': '123456',
            'database': 'appx',
            'port': 3310
        }
        self.db=pymysql.connect(cursorclass=pymysql.cursors.DictCursor,**db)
        self.cur=self.db.cursor()
    def userMysql(self,sql):
        try:
            self.cur.execute(sql)
            texts=self.cur.fetchall()
            if texts:
                return texts
            else:
                self.db.commit()
                print('提交成功')
        except Exception as e:
            print(e)
            self.db.rollback()
        finally:
            self.db.close()

if __name__ == '__main__':
    UserMysql()
